<!DOCTYPE html>
<html>
    <head>
        <title>Point Cloud on globe</title>

        <style type="text/css">
            #info {
                color: #7ad7ff;
                font-family: 'Open Sans', sans-serif;
                position: absolute;
                top: 0;
                left: 0;
                padding: 0.3rem;
                background-color: #404040;
                z-index: 1;
            }

            @media (max-width: 600px) {
                #info,
                .dg {
                    display: none;
                }
            }
        </style>

        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="css/example.css">
        <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div id="viewerDiv"></div>
        <div id="info"></div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
        <script src="../dist/itowns.js"></script>
        <script src="js/GUI/LoadingScreen.js"></script>
        <script src="../dist/debug.js"></script>
        <script type="text/javascript">
            var potreeLayer;
            var oldPostUpdate;
            var viewerDiv;
            var debugGui;
            var view;

            viewerDiv = document.getElementById('viewerDiv');
            viewerDiv.style.display = 'block';

            debugGui = new dat.GUI();

            var placement = {
                coord: new itowns.Coordinates('EPSG:4326',  4.631512, 43.675626),
                range: 100,
                tilt: 45,
                heading: -60
            }

            view = new itowns.GlobeView(viewerDiv, placement, { handleCollision: false });
            setupLoadingScreen(viewerDiv, view);

            view.controls.minDistance = 50;

            // Configure Point Cloud layer
            potreeLayer = new itowns.PotreeLayer('eglise_saint_blaise_arles', {
                source: new itowns.PotreeSource({
                    file: 'eglise_saint_blaise_arles.js',
                    url: 'https://raw.githubusercontent.com/gmaillet/dataset/master/',
                    crs: view.referenceCrs,
                }),
            });

            // add potreeLayer to scene
            function onLayerReady() {
                debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);

                // update stats window
                var info = document.getElementById('info');
                view.addFrameRequester(itowns.MAIN_LOOP_EVENTS.AFTER_RENDER, () => {
                    info.textContent = potreeLayer.displayedCount.toLocaleString() + ' points';
                });
            }
            window.view = view;

            itowns.View.prototype.addLayer.call(view, potreeLayer).then(onLayerReady);

            itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(function _(config) {
                config.source = new itowns.WMTSSource(config.source);
                var layer = new itowns.ElevationLayer(config.id, config);
                view.addLayer(layer);
            });
            itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
                config.source = new itowns.WMTSSource(config.source);
                var layer = new itowns.ColorLayer(config.id, config);
                view.addLayer(layer);
            });
        </script>
    </body>
</html>

